package org.xiyu.yee.beacon_anti_phantom;

import org.xiyu.yee.beacon_anti_phantom.platform.Services;
import org.xiyu.yee.beacon_anti_phantom.config.BeaconConfig;
import org.xiyu.yee.beacon_anti_phantom.beacon.BeaconManager;
import org.xiyu.yee.beacon_anti_phantom.particle.ParticleManager;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.Items;

// This class is part of the common project meaning it is shared between all supported loaders. Code written here can only
// import and access the vanilla codebase, libraries used by vanilla, and optionally third party libraries that provide
// common compatible binaries. This means common code can not directly use loader specific concepts such as Forge events
// however it will be compatible with all supported mod loaders.
public class CommonClass {

    // The loader specific projects are able to import and use any code from the common project. This allows you to
    // write the majority of your code here and load it from your loader specific projects. This example has some
    // code that gets invoked by the entry point of the loader specific projects.
    public static void init() {
        Constants.LOG.info("Hello from Common init on {}! we are currently in a {} environment!", Services.PLATFORM.getPlatformName(), Services.PLATFORM.getEnvironmentName());
        Constants.LOG.info("The ID for diamonds is {}", BuiltInRegistries.ITEM.getKey(Items.DIAMOND));
        
        // 初始化信标反幻翼模组
        initBeaconAntiPhantom();

        // It is common for all supported loaders to provide a similar feature that can not be used directly in the
        // common code. A popular way to get around this is using Java's built-in service loader feature to create
        // your own abstraction layer. You can learn more about this in our provided services class. In this example
        // we have an interface in the common code and use a loader specific implementation to delegate our call to
        // the platform specific approach.
        if (Services.PLATFORM.isModLoaded("beacon_anti_phantom")) {
            Constants.LOG.info("Hello to beacon_anti_phantom");
        }
    }
    
    private static void initBeaconAntiPhantom() {
        Constants.LOG.info("Initializing Beacon Anti-Phantom mod...");
        
        // 初始化配置
        BeaconConfig.getInstance();
        
        // 加载配置文件
        org.xiyu.yee.beacon_anti_phantom.config.ConfigManager.loadConfig();
        
        Constants.LOG.info("Beacon configuration loaded:");
        BeaconConfig.getInstance().getAllRadius().forEach((level, radius) -> 
            Constants.LOG.info("  Level {} beacon radius: {} blocks", level, radius));
        
        // 初始化管理器
        BeaconManager.getInstance();
        ParticleManager.getInstance();
        
        Constants.LOG.info("Beacon Anti-Phantom mod initialized successfully!");
        Constants.LOG.info("Phantoms entering beacon protection areas will be attacked with particle beams!");
        Constants.LOG.info("Attack effects are handled by ServerChunkCacheMixin for better performance!");
    }
}
